/**
 *
 */
package ar.com.mun.rowProcessors;

import ar.com.mun.beans.SEMCUser;
import ar.com.mun.daos.SEMCUserDAO;

import com.angel.common.helpers.StringHelper;
import com.angel.data.generator.annotations.Inject;
import com.angel.io.annotations.ColumnRow;
import com.angel.io.annotations.RowChecker;
import com.angel.io.annotations.RowProcessor;
import com.angel.io.annotations.RowProcessorCommand;
import com.angel.io.exceptions.InvalidRowDataException;

/**
 * @author William
 *
 */
@RowProcessorCommand
	(
		columnsRow = {
			@ColumnRow( columnName = SEMCUserAnnotationRowProcessorCommand.NUMERO_INTERNO_COLUMN, aliases = {"Numero Interno"} ),
			@ColumnRow( columnName = SEMCUserAnnotationRowProcessorCommand.NAME_COLUMN, aliases = {"Nombre de usuario"}),
			@ColumnRow( columnName = SEMCUserAnnotationRowProcessorCommand.PASSWORD_COLUMN, aliases = {"Password"}),
			@ColumnRow( columnName = SEMCUserAnnotationRowProcessorCommand.EMAIL_COLUMN, aliases = {"Correo Electronico"}),
			@ColumnRow( columnName = SEMCUserAnnotationRowProcessorCommand.ACTIVE_COLUMN, aliases = {"Activo"}, type = Boolean.class)
		}
	)
public class SEMCUserAnnotationRowProcessorCommand {

	public static final String NUMERO_INTERNO_COLUMN = "numeroInterno";
	public static final String NAME_COLUMN = "name";
	public static final String PASSWORD_COLUMN = "password";
	public static final String EMAIL_COLUMN = "email";
	public static final String ACTIVE_COLUMN = "active";

	@Inject(beanName = "semcUserDAO")
	private SEMCUserDAO semcUserDAO;
	
    @RowChecker(columnsParameters = {})
    public void checkRowData(String numeroInterno, String nombreUsuario, String password, String email, Boolean activo) throws InvalidRowDataException {
		boolean areAllNotEmpty = StringHelper.areAllNotEmpty(numeroInterno, nombreUsuario, password, email, activo.toString());
		if(!areAllNotEmpty){
			throw new InvalidRowDataException("Some row data are NULL - " +
					"numeroInterno: [" + numeroInterno+ "] - " +
					"nombreUsuario: [" + nombreUsuario+ "] - " +
					"password: [" + password+ "] - " +
					"email: [" + email+ "] - " +
					"activo: [" + activo + "].");
		}
		SEMCUser semcUser = this.getSemcUserDAO().buscarUnicoOrNuloPorNumeroInterno(numeroInterno);
		if(semcUser != null){
			throw new InvalidRowDataException("SEMC user exist with numero interno[" + numeroInterno + "].");
		}
    }

	@RowProcessor(columnsParameters = {}, object = SEMCUser.class, inject = true)
	public SEMCUser processRow(SEMCUser user, String numeroInterno, String nombreUsuario, String password, String email, Boolean activo) {
        return user;
    }

	/**
	 * @return the semcUserDAO
	 */
	public SEMCUserDAO getSemcUserDAO() {
		return semcUserDAO;
	}

	/**
	 * @param semcUserDAO the semcUserDAO to set
	 */
	public void setSemcUserDAO(SEMCUserDAO semcUserDAO) {
		this.semcUserDAO = semcUserDAO;
	}
}
